package com.bs.sc.front.goodsCar.dao;

import java.util.List;
import java.util.Map;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import com.bs.sc.front.goodsCar.entity.GoodsCar;
import com.bs.sc.front.user.entity.User;

@Repository("goodsCarDao")
public interface GoodsCarDao extends JpaRepository<GoodsCar, String> {

	@Query(value = "SELECT a.id as carId,a.user_id as userId,b.goods_id as goodsId,b.goods_car_id as goodsCarId,b.count as count,b.id as itemId FROM goods_car a,goods_car_item b WHERE a.id = b.goods_car_id AND a.user_id = ?1 AND b.goods_id = ?2", nativeQuery = true)
	List<Map<String, Object>> findByUserIdAndGoodsId(String userId, String goodsId);

	@Query(value = "SELECT a.id as carId,a.user_id as userId,b.goods_id as goodsId,b.goods_car_id as goodsCarId,b.count as count,b.id as itemId FROM goods_car a,goods_car_item b WHERE a.id = b.goods_car_id AND a.user_id = ?1", nativeQuery = true)
	List<Map<String, Object>> findByUserId(String userId);

	@Query(value = "SELECT a.id AS carId,a.user_id AS userId,b.goods_id AS goodsId,b.goods_car_id AS goodsCarId,b.count AS count,b.id AS itemId FROM goods_car a,goods_car_item b WHERE a.id = b.goods_car_id AND a.user_id = ?1 AND b.goods_id IN ?2", nativeQuery = true)
	public List<Map<String, Object>> findOrderGoods(String userId, String[] idList);

	public List<GoodsCar> findByUser(User user);
}
